# 接下来，我们更进一步，创建一个更复杂的模拟。 假设我们只有两个工作进程，一次只能制作两个汉堡。

import asyncio
import time

order_queue = asyncio.Queue()


def take_order():
    for i in range(5):
        order_queue.put_nowait(make_burger(i))


async def make_burger(order_num):
    print(f"Preparing burger #{order_num}")
    await asyncio.sleep(5)
    print(f"burger made #{order_num}")


class Staff:
    def __init__(self, name):
        self.name = name

    async def working(self):
        while order_queue.qsize() > 0:
            print(f'{self.name} is working...')
            task = await order_queue.get()
            await task
            print(f'{self.name} finished a task...')


async def main():
    staff1 = Staff(name="John")
    staff2 = Staff(name="Jane")
    take_order()
    await asyncio.gather(staff1.working(), staff2.working())


if __name__ == '__main__':
    s = time.perf_counter()
    asyncio.run(main())
    elapsed = time.perf_counter() - s
    print(f"Finished in {elapsed:.2f} seconds.")
